package com.hp.ssm.service.impl;

import com.hp.ssm.entity.User;
import com.hp.ssm.mapper.PersonMapper;
import com.hp.ssm.service.LoginService;
import com.hp.ssm.util.DBHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 23129
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Resource
    private PersonMapper personMapper;

    @Override
    public Map login(User user) {
        return personMapper.login(user);
    }

    @Override
    public List<Map> getPermissions(Integer aid) {
        DBHelper dbHelper = DBHelper.getMyHepler();
        String sql = "select distinct p.* from user u left join adminrole ar on u.aid = ar.aid left join rolepermissions rp on rp.rid = ar.rid left join permissions p on rp.permissionsidNo = p.permissionsidNo where u.aid = ?";
        return dbHelper.select(sql, aid);
    }

    @Override
    public User checkUser(String ausername) {
        return personMapper.checkUser(ausername);
    }
}
